package mi.payment.ui.admin;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import mi.payment.R;
import mi.payment.ui.base.ParentActivity;
import mi.payment.ui.director.OperatorAdministratorActivity;
import mi.payment.ui.director.UpdatePasswordActivity;
import sunmi.sunmiui.title.Title;

/**
 * 修改密码界面
 */
public class PasswordManagementActivity extends ParentActivity {

    private View modifySafetyPasswordView, modifyAdministratorPasswordView, modifySystemPasswordView, modifyGeneralPasswordView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_password_management);
        initView();
        setClickListener();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        Title title;
        TextView leftText;
        title = (Title) findViewById(R.id.password_management_title);
        modifySystemPasswordView = findViewById(R.id.modify_system_password);
        modifyAdministratorPasswordView = findViewById(R.id.modify_administrator_password);
        modifyGeneralPasswordView = findViewById(R.id.modify_general_password);
        modifySafetyPasswordView = findViewById(R.id.modify_safety_password);

        leftText = (TextView) modifySystemPasswordView.findViewById(R.id.item_left_text);
        leftText.setText(getResources().getString(R.string.modify_system_password));

        leftText = (TextView) modifyAdministratorPasswordView.findViewById(R.id.item_left_text);
        leftText.setText(getResources().getString(R.string.modify_administrator_password));

        leftText = (TextView) modifyGeneralPasswordView.findViewById(R.id.item_left_text);
        leftText.setText(getResources().getString(R.string.modify_general_password));

        leftText = (TextView) modifySafetyPasswordView.findViewById(R.id.item_left_text);
        leftText.setText(getResources().getString(R.string.modify_safety_password));

        title.setButtonVisibility(false, true, true, true);
        title.setHeadBgColor(getResources().getColor(R.color.colorBar));
        title.setTitleText(getResources().getString(R.string.password_management));

        title.setMenuClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }

        }, null, null, null);
    }

    private void setClickListener() {
        modifySystemPasswordView.setOnClickListener(this);
        modifyAdministratorPasswordView.setOnClickListener(this);
        modifyGeneralPasswordView.setOnClickListener(this);
        modifySafetyPasswordView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.modify_system_password:
                // 修改管理员界面
                intent.setClass(this, UpdatePasswordActivity.class);
                intent.putExtra("user_info", mUserInfoModel.queryUserInfoById("99"));
                // 一般操作员传1，系统操作员传3
                intent.putExtra("who_update", 3);
                startActivity(intent);
                break;
            case R.id.modify_administrator_password:
                intent.setClass(this, UpdatePasswordActivity.class);
                intent.putExtra("user_info", mUserInfoModel.queryUserInfoById("00"));
                intent.putExtra("who_update", 2);
                startActivity(intent);
                break;
            case R.id.modify_general_password:
                openActivity(OperatorAdministratorActivity.class);
                break;
            case R.id.modify_safety_password:
                // 修改安全密码
                intent.setClass(this, UpdateSecurityPasswordActivity.class);
                startActivity(intent);
                break;
        }
    }
}
